#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSystemTrayIcon>
#include <utils/config.h>
#include <crypto/cryptomanager.h>
#include <crypto/secureDataMap.h>
#include <users/user.h>

#include <data_display/accountDataDialog.h>
#include <data_display/totpwindow.h>
#include <utils/clipboardwatcher.h>
#include <utils/popup.h>
#include <totp/totp.h>
#include <totp/totpManager.h>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

namespace main_window {
class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	MainWindow(utils::config& config,QWidget *parent = nullptr);
	~MainWindow();

protected:
	void closeEvent(QCloseEvent *event) override;

	public slots:
		void setUser(const users::user& user);

private slots:
	void on_saveButton_clicked();

	void addDataToSecureDataMap(const crypto::SecureDataMapItem& item);

	void openAccWindow();

	void showClearedPopup();

	void on_totpButton_clicked();

	void addTOTP(const totp::TOTP& totp);

	void deleteTOTP(const totp::TOTP& totp);

	void showContextMenu(const QPoint &pos);

	void trayIconActivated(QSystemTrayIcon::ActivationReason reason);

	void openTotp();

private:
	void fillTable();
	void createContextMenu();
	void copyPassword();
	void deleteRow();
	void createTrayIcon();

	QSystemTrayIcon *trayIcon;
	QMenu *trayIconMenu;
	QMenu *tableContextMenu;
	QAction *copyPasswordAction;
	QAction *deleteRowAction;
	QAction *minimizeAction;
	QAction *restoreAction;
	QAction *quitAction;
	QAction *openTotpAction;
	Ui::MainWindow *ui;
	std::unique_ptr<crypto::SecureDataMap> _sdm;
	std::unique_ptr<crypto::cryptomanager> _manag;
	std::unique_ptr<totp::TOTPManager> _totpManager;
	utils::config& _config;
	utils::PopUp *_popup;
	users::user _user;
	utils::ClipboardWatcher _clipboard_watcher;
	bool _data_clicked;
	data_display::accountDataDialog *_dataDialog;
	data_display::TOTPWindow *_totpDialog;
};
}
#endif // MAINWINDOW_H
